﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DTcms.Web.api.payment.paypal
{
    public partial class _return : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string payerid = Request.QueryString.Get("PayerId");
            string token = Request.QueryString.Get("Token");
            string action = Request.QueryString.Get("action");
            string order_no = Request.QueryString.Get("orderno");
            string tid = "";

            if (string.IsNullOrEmpty(action) && !string.IsNullOrEmpty(token) && !string.IsNullOrEmpty(payerid))
            {
                var payPalReturn = new API.Payment.paypal.PayPalReturn();
                var vailresult = payPalReturn.ResultVail(token,payerid,out tid);

                if (vailresult)
                {
                    Response.Redirect(new Web.UI.BasePage().linkurl("payment", "?action=succeed&order_no=" + order_no));
                }
                else 
                {
                    Response.Redirect(new Web.UI.BasePage().linkurl("payment", "?action=error"));
                }
            }
            else if (action.Equals("cancel"))
            {
                Response.Redirect(new Web.UI.BasePage().linkurl("payment", "?action=error"));
            }
        }
    }
}